package ErbeDesKoenigs;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import objects.PlayerInfo;

public class Surface extends JPanel implements ActionListener{

	private GridLayout gl = new GridLayout(2, 2);
	private JButton nextPlayer = new JButton("Next Player");
	
	private int playerNumber = 0;

	public Surface(int playerNumber) {
		this.playerNumber = playerNumber;
		nextPlayer.addActionListener(this);
		nextPlayer.setActionCommand("nextPlayer");
		this.setSize(ErbeDesKoenigs.windowX, ErbeDesKoenigs.windowY/2);
		refresh();
		this.setVisible(false);
	}

	public void refresh() {
		
		this.setBackground(Color.white);
		this.setLayout(gl);
		this.add(new JLabel("Player "+(playerNumber+1)), gl);
		this.add(new JLabel(" "), gl);
		this.add(new JLabel(" "), gl);
		this.add(nextPlayer, gl);
		
		this.repaint();
		ErbeDesKoenigs.myWin.repaint();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("nextPlayer")){
			ErbeDesKoenigs.activePlayer = ((ErbeDesKoenigs.activePlayer+1)%ErbeDesKoenigs.playerCount);
			ErbeDesKoenigs.myWin.showActivePlayer();
		}
	}
}
